<?php

namespace app\service\category;

use app\service\base\BaseModel;
use think\facade\Db;

class CategoryModel extends BaseModel
{
    protected $name = 'category';

    public function getAll()
    {
        return Db::name($this->name)
            ->order('pid', 'asc')
            ->order('sort', 'desc')
            ->order('id', 'asc')
            ->select()
            ->toArray();
    }

    public function getAllByIds($arrIds)
    {
        return Db::name($this->name)
            ->where('id', 'in', $arrIds)
            ->order('pid', 'asc')
            ->order('sort', 'desc')
            ->order('id', 'asc')
            ->select()
            ->toArray();
    }

    public function add($arrData)
    {
        return Db::name($this->name)->insert($arrData);
    }

    public function edit($id, $arrData)
    {
        return Db::name($this->name)->where('id', $id)->update($arrData);
    }

    public function getRow($arrWhere)
    {
        return Db::name($this->name)->where($arrWhere)->find();
    }

    public function delById($id)
    {
        return Db::name($this->name)->where('id', $id)->delete();
    }
}